<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Transaksi - Faktur Penjualan</title>
<link href="<?php echo base_url(); ?>assets/css/style-trx.css" rel="stylesheet" type="text/css"/>
	<link rel="stylesheet" href="<?php echo base_url()?>assets/jqueryui/themes/jquery.ui.all.css">
	<style>
	.ui-tooltip, .arrow:after {
		background: black;
		border: 2px solid white;
	}
	.ui-tooltip {
		padding: 10px 20px;
		color: white;	
		border-radius: 20px;
		font: bold 14px "Helvetica Neue", Sans-Serif;
		text-transform: uppercase;
		box-shadow: 0 0 7px black;
	}
	.arrow {
		width: 70px;
		height: 16px;
		overflow: hidden;
		position: absolute;
		left: 50%;
		margin-left: -35px;
		bottom: -16px;
	}
	.arrow.top {
		top: -16px;
		bottom: auto;
	}
	.arrow.left {
		left: 20%;
	}
	.arrow:after {
		content: "";
		position: absolute;
		left: 20px;
		top: -20px;
		width: 25px;
		height: 25px;
		box-shadow: 6px 5px 9px -9px black;
		-webkit-transform: rotate(45deg);
		-moz-transform: rotate(45deg);
		-ms-transform: rotate(45deg);
		-o-transform: rotate(45deg);
		tranform: rotate(45deg);
	}
	.arrow.top:after {
		bottom: -20px;
		top: auto;
	}
	</style>
</head>
<body style="background:#CCC; font-size:70%;">
<center>
<div class="kanvas">
<div class="trx-title"><a href="<?php echo site_url()?>/home">Home</a> &raquo; Transaksi &raquo; <a href="<?php echo site_url()?>/transaksi/status_so/tampil_nontender">Status SO</a> &raquo; Sales Order Out</div>
<div class="trx">
<?php
if(!empty($ses_noso)){
	$kdcus1 = $row1->pelanggan_id;
	$kdcus2 = $row2->pelanggan_id;
	$nama1  = $row1->nama;
	$nama2  = $row2->nama;
	$alamat1 = $row1->alamat;
	$alamat2 = $row2->alamat;
	$kota1 = $row1->kota;
	$kota2 = $row2->kota;
	$tlp1 = $row1->tlp;
	$tlp2 = $row2->tlp;
	$npwp = $row1->npwp;
	$tender = $rowfaktur->tender;
	$jnstrn = $rowfaktur->tipetrn;
	$tgl      = date("d-m-Y",strtotime($rowfaktur->tanggal));
	$sales_id = $rowfaktur->sales_id;
	$nama_sales = $rowfaktur->nama_sales;
	$readonly = "READONLY";
}else{
	$kdcus1 = "";
	$kdcus2 = "";
	$nama1  = "";
	$nama2  = "";
	$alamat1 = "";
	$alamat2 = "";
	$kota1 = "";
	$kota2 = "";
	$sales_id = "";
	$nama_sales = "";
	$tlp1 = "";
	$tlp2 = "";
	$npwp = "";
	$tender = "";
	$jnstrn = "";
	$readonly = "";
	$tgl  = date("d-m-Y");
}
?>
<table width="100%" class="trx-form">
<tr>
	<td width="9%" height="20"><strong>Pilih Pelanggan</strong></td>
    <td width="16%">
    	<input type="hidden" name="pelanggan_id1" id="kdcus1" value="<?php echo $kdcus1;?>"/>
    	<input type="text" class="input" id="nama1" name="nama1" value="<?php echo $nama1;?>" <?php echo $readonly?>/>
    </td>
    <td width="1%">
    </td>
    <td width="5%"><strong>Untuk</strong></td>
    <td width="17%">
    	<input type="hidden" name="pelanggan_id2" id="kdcus2" value="<?php echo $kdcus2;?>"/>
    	<input type="text" name="nama2" class="input" id="nama2" value="<?php echo $nama2;?>" <?php echo $readonly?>/>
    </td>
    <td width="2%">
    </td>
    <td width="7%"><strong>Sales</strong></td>
    <td width="17%">
    	<input type="hidden" name="sales_id" id="sales_id" value="<?php echo $sales_id;?>"/>
    	<input type="text" name="nama_sales" class="input" id="nama_sales" value="<?php echo $nama_sales;?>" <?php echo $readonly?>/>
    </td>
    <td width="3%">
    </td>
    <td width="6%"><strong>No. So</strong></td>
    <td width="17%"><input name="noso" type="text" class="input center" id="noso" placeholder="No So.." 
    	value="<?php echo $noso; ?>" readonly="readonly"/></td>
    </tr>
<tr>
	<td width="9%" height="20"></td>
    <td width="16%">
    	<input type="text" placeholder="Alamat.." class="input" name="alamat1" id="alamat1" value="<?php echo $alamat1;?>" <?php echo $readonly?>/>
    </td>
    <td width="1%">
    </td>
    <td width="5%"></td>
    <td width="17%">
    	<input type="text" placeholder="Alamat.." class="input" name="alamat2" id="alamat2" value="<?php echo $alamat2;?>" <?php echo $readonly?>/>
    </td>
    <td width="2%">
    </td>
    <td width="7%"></td>
    <td width="17%">
    	<input type="text" placeholder="Alamat.." class="input" name="alamat3" id="alamat3" value="<?php echo $alamat2;?>" <?php echo $readonly?>/>
    </td>
    <td width="3%">
    </td>
    <td><strong>No. Faktur</strong></td>
    <td><input type="text" name="nofaktur" placeholder="No Faktur.." value="" class="input center"/></td>
    </tr>
<tr>
	<td width="9%" height="20"></td>
    <td width="16%">
    	<input type="text" placeholder="Kota.." class="input" name="kota1" id="kota1" value="<?php echo $kota1;?>" <?php echo $readonly?>/>
    </td>
    <td width="1%">
    </td>
    <td width="5%"></td>
    <td width="17%">
    	<input type="text" placeholder="Kota.." class="input" name="kota2" id="kota2" value="<?php echo $kota2;?>" <?php echo $readonly?>/>
    </td>
    <td width="2%">
    </td>
    <td width="7%"></td>
    <td width="17%">
    	<input type="text" placeholder="Kota.." class="input" name="kota3" id="kota3" value="<?php echo $kota2;?>" <?php echo $readonly?>/>
    </td>
    <td width="3%">
    </td>
    <td width="6%"><strong>Tender</strong></td>
    <td width="17%">
    	<select name="tender">
        <option value="1" <?php if($tender == '1') echo "selected"; ?>>Tender </option>
        <option value="2" <?php if($tender == '2') echo "selected"; ?>>Non Tender </option>
        </select>
    </td>
</tr>
<tr>
	<td width="9%" height="20"></td>
    <td width="16%">
    	<input type="text" placeholder="Tlp.." class="input" name="tlp1" id="tlp1" value="<?php echo $tlp1;?>" <?php echo $readonly?>/>
    </td>
    <td width="1%">
    </td>
    <td width="5%"></td>
    <td width="17%">
    	<input type="text" placeholder="Tlp.." class="input" name="tlp2" id="tlp2" value="<?php echo $tlp2;?>" <?php echo $readonly?>/>
    </td>
    <td width="2%">
    </td>
    <td width="7%"></td>
    <td width="17%">
    	<input type="text" placeholder="Tlp.." class="input" name="tlp3" id="tlp3" value="<?php echo $tlp2;?>" <?php echo $readonly?>/>
    </td>
    <td width="3%">
    </td>
    <td width="6%"><strong>Jenis</strong></td>
    <td width="17%"><input type="radio" name="tipetrn" value="1" <?php if($jnstrn == '1') echo "checked".' '.$readonly;?>/>
      Ins
      <input type="radio" name="tipetrn" value="2" <?php if($jnstrn == '2') echo "checked".' '.$readonly;?>/>
      Reg </td>
    </tr>
<tr>
	<td width="9%" height="20"><strong>NPWP</strong></td>
    <td width="16%">
    	<input type="text" class="input" name="npwp" value="<?php echo $npwp; ?>" <?php echo $readonly?>/>
    </td>
    <td width="1%">
    </td>
    <td width="5%">&nbsp;</td>
    <td width="17%">
    	<input type="text" class="input"/>
    </td>
    <td width="2%">
    </td>
    <td width="7%">&nbsp;</td>
    <td width="17%">
    	<input type="text" class="input"/>
    </td>
    <td width="3%">
    </td>
    <td width="6%"><strong>Tanggal</strong></td>
    <td width="17%"><input type="text" name="tgl" class="input center" value="<?php echo $tgl; ?>" readonly="readonly"/></td>
    </tr>
</table>
<hr />
<?php
$attributes = array('name' => 'f_so','onSubmit' => 'return validate(this)','id' => 'f_submit');
echo form_open('transaksi/sales_order_out/simpan',$attributes);
?>
<table width="100%" cellspacing="0" border="0" class="trx-table">
<tr height="25">
	<td width="10%" align="center" valign="middle"><strong>Kode</strong></td>
	<td width="20%" align="center" valign="middle"><strong>Nama</strong></td>
	<td width="8%" align="center" valign="middle"><strong>Satuan</strong></td>
	<td width="8%" align="center" valign="middle"><strong>Harga</strong></td>
	<td width="8%" align="center" valign="middle"><strong>Qty</strong></td>
	<td width="8%" align="center" valign="middle"><strong>Diskon</strong></td>
	<td width="10%" align="center" valign="middle"><strong>Harga</strong></td>
	<td width="10%" align="center" valign="middle"><strong>Qty</strong></td>
	<td width="10%" align="center" valign="middle"><strong>Diskon</strong></td>
	<td width="8%" align="center" valign="middle"><strong>Total</strong></td>
</tr>
</table>
<div style="width:100%; height:150px; overflow:auto; border-bottom:1px solid #000;" />
<?php
if(!empty($fakturdetail)){

$nmr = 0;
foreach($fakturdetail as $res){
?>
<table width="100%" cellspacing="0" border="0" class="trx-table-detail">
<tr height="28">
	<td width="10%" align="center"><input type="hidden" name="prokode<?php echo $nmr;?>" value="<?php echo $res->prokode;?>" /><?php echo $res->prokode;?></td>
	<td width="20%" align="left">&nbsp;<?php echo $res->nama;?></td>
	<td width="8%" align="center"><?php echo $res->satuan;?></td>
	<td width="8%" align="right"><input type="hidden" name="harga1<?php echo $nmr;?>" value="<?php echo $res->price;?>" /><?php echo number_format($res->price,0,'','.');?>&nbsp;</td>
	<td width="8%" align="center"><input type="hidden" name="qty1 <?php echo $nmr;?>" value="<?php echo $res->qty;?>"/><?php echo $res->qty;?></td>
	<td width="8%" align="center"><input type="hidden" name="diskon1 <?php echo $nmr;?>" /><?php echo $res->diskon;?></td>
	<td width="10%" align="center"><input type="text" onkeyup='out(<?php echo $nmr;?>)' name="harga2<?php echo $nmr;?>" style="width:95%; text-align:right;" value="<?php echo number_format($res->price,0,'','.');?>"></td>
	<td width="10%" align="center"><input type="text" onkeyup='out(<?php echo $nmr;?>)' name="qty2<?php echo $nmr;?>" style="width:95%; text-align:center;" value="<?php echo $res->qty;?>"></td>
	<td width="10%" align="center"><input type="text" onkeyup='out(<?php echo $nmr;?>)' name="diskon2<?php echo $nmr;?>" style="width:95%; text-align:center;" value="<?php echo $res->diskon;?>"></td>
	<td width="8%" align="right"><input readonly type="text" name="total2<?php echo $nmr;?>" style="width:95%; text-align:right;" value="<?php echo number_format($res->total,0,'','.');?>"></td>
</tr>
</table>
<?php 
$nmr++;
}
?>
<input name='nm' type='hidden' id='nm' value='<?php echo $nmr; ?>'>
<input name='soid' type='hidden' value='<?php echo $noso; ?>'>
<?php 
}
?>
</div>
<div align="left">
<?php
if(!empty($ses_noso)){
	$total1= $rowfaktur->total_1;
	$ppn   = $rowfaktur->ppn;
	$total = $rowfaktur->total;
	$potongan = $rowfaktur->potongan;
	$b_kirim = $rowfaktur->b_kirim;
	$kerjasama = $rowfaktur->kerjasama;
	$total_2 = $rowfaktur->total_2;
	$materai = $rowfaktur->materai;
}else{
	$total1= 0;
	$ppn   = 0;
	$total = 0;
	$potongan = 0;
	$b_kirim = 0;
	$kerjasama = 0;
	$total_2 = 0;
	$materai = 0;
}
?>
<table class="trx-form">
	<tr>
	  	<td><strong>Total 1</strong></td>
		<td><input type="text" name="total_1" class="input right" value="<?php echo number_format($total1,0,'','.');?>"/></td>
	  	<td><strong>PPn</strong></td>
		<td><input type="text" name="ppn" class="input right" value="<?php echo number_format($ppn,0,'','.');?>"/></td>
	  	<td><strong>Jumlah Tagihan</strong></td>
		<td><input type="text" name="nettoppn" class="input right" value="<?php echo number_format($total,0,'','.');?>"/></td>
    </tr>
	<tr>
	  	<td><strong>Potongan</strong></td>
		<td><input type="text" name="potongan" class="input right" value="<?php echo number_format($potongan,0,'','.');?>"/></td>
	  	<td><strong>Biaya Kirim</strong></td>
		<td><input type="text" class="input right" value="<?php echo number_format($b_kirim,0,'','.');?>"/></td>
	  	<td><strong>Kerjasama</strong></td>
		<td><input type="text" class="input right" value="<?php echo number_format($kerjasama,0,'','.');?>"/></td>
    </tr>
	<tr>
	  	<td><strong>Total 2</strong></td>
		<td><input name="total_2" type="text" class="input right" value="<?php echo number_format($total_2,0,'','.');?>" /></td>
	  	<td><strong>Materai</strong></td>
		<td><input type="text" class="input right" value="<?php echo number_format($materai,0,'','.');?>"/></td>
    </tr>
    <tr height="25"></tr>
	<tr>
    	<td colspan="4">
        <input type="button" class="tombol" value="Tambah" onclick="tambah()"/>
        <input type="submit" name="simpan" class="tombol" value="Simpan"/>
        </td>
    </tr>
</table>
<?php echo form_close(); ?>
</div>
</div>
</center>
</body>
</html>
	<script src="<?php echo base_url()?>assets/jqueryui/jquery-1.9.1.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.core.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.widget.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.position.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.menu.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.autocomplete.js"></script>
    <script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.datepicker.js"></script>
   	<script src="<?php echo base_url()?>assets/jqueryui/ui/jquery.ui.tooltip.js"></script>
    <script>
	$(function() {
		$( document ).tooltip({
			position: {
				my: "center bottom-20",
				at: "center top",
				using: function( position, feedback ) {
					$( this ).css( position );
					$( "<div>" )
						.addClass( "arrow" )
						.addClass( feedback.vertical )
						.addClass( feedback.horizontal )
						.appendTo( this );
				}
			}
		});

	});

	var site = "<?php echo site_url();?>";
	$(function() {
		$("#prokode").autocomplete({
		source: site+"/transaksi/search/barang",	
		minLength: 1,
		select: function(event, ui) {
			var hasil = ui.item.value.split('-');
			$('#prokode').val(hasil[0]);
			$('#nama').val(hasil[1]);
			$('#qty').val('1');
			$('#harga').val(hasil[2]);
			$('#satuan').val(hasil[3]);
			$('#total').val(hasil[2]*1);
			return false;
		}
		});
	});

	var site = "<?php echo site_url();?>";
	$(function() {
		$("#nama1").autocomplete({
		source: site+"/transaksi/search/pelanggan",	
		minLength: 1,
		select: function(event, ui) {
			var hasil = ui.item.value.split('-');
			$('#kdcus1').val(hasil[0]);
			$('#nama1').val(hasil[1]);
			$('#alamat1').val(hasil[2]);
			$('#kota1').val(hasil[3]);
			$('#tlp1').val(hasil[4]);
			return false;
		}
		});
	});

	var site = "<?php echo site_url();?>";
	$(function() {
		$("#nama2").autocomplete({
		source: site+"/transaksi/search/pelanggan",	
		minLength: 1,
		select: function(event, ui) {
			var hasil = ui.item.value.split('-');
			$('#kdcus2').val(hasil[0]);
			$('#nama2').val(hasil[1]);
			$('#alamat2').val(hasil[2]);
			$('#kota2').val(hasil[3]);
			$('#tlp2').val(hasil[4]);
			return false;
		}
		});
	});

	var site = "<?php echo site_url();?>";
	$(function() {
		$("#nama_sales").autocomplete({
		source: site+"/transaksi/search/sales",	
		minLength: 1,
		select: function(event, ui) {
			var hasil = ui.item.value.split('-');
			$('#sales_id').val(hasil[0]);
			$('#nama_sales').val(hasil[1]);
			$('#alamat3').val(hasil[2]);
			$('#kota3').val(hasil[3]);
			$('#tlp3').val(hasil[4]);
			return false;
		}
		});
	});
		
function formatNumber (obj, decimal) {
	anynum=eval(obj.value);
	divider =10;
	switch(decimal){
		case 0:
			divider =1;
			break;
		case 1:
			divider =10;
			break;
		case 2:
			divider =100;
			break;
		default:  	 //for 3 decimal places
			divider =1000;
	}
	workNum=Math.abs((Math.round(anynum*divider)/divider));
	workStr=""+workNum
	if (workStr.indexOf(".")==-1){workStr+="."}
	dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
	pStr=workStr.substr(workStr.indexOf("."))
	while (pStr.length-1< decimal){pStr+="0"}
	if(pStr =='.') pStr ='';
	//--- Adds a comma in the thousands place.    
	if (dNum>=1000) {
		dLen=dStr.length
		dStr=parseInt(""+(dNum/1000))+"."+dStr.substring(dLen-3,dLen)
	}
	//-- Adds a comma in the millions place.
	if (dNum>=1000000) {
		dLen=dStr.length
		dStr=parseInt(""+(dNum/1000000))+"."+dStr.substring(dLen-7,dLen)
	}
	retval = dStr + pStr
	//-- Put numbers in parentheses if negative.
	if (anynum<0) {retval="("+retval+")";}
	//retval =  "$"+retval
	obj.value = retval;
}

function format_harga() {
  var harga = document.f_so.harga.value;
  harga = harga.replace(/[^0-9.]/g,"");
  harga = harga.replace(".","");
  harga = harga.replace(".","");
  if(harga.length == 0) harga = "0";	

  var qty = document.f_so.qty.value;
  qty = qty.replace(/[^0-9.]/g,"");
  qty = qty.replace(".","");
  qty = qty.replace(".","");
  if(qty.length == 0) qty = "0";	
  
  var total = harga * qty;

  if(qty.length > 0) {
    if(!isNaN(qty)) {
      document.f_so.harga.value = harga;
      document.f_so.qty.value = qty;
      document.f_so.total.value = total;
      formatNumber(document.f_so.harga,0);
      formatNumber(document.f_so.qty,0);
      formatNumber(document.f_so.total,0);
     }	
  } else { document.f_so.qty.value = "0"; }			

}

function format_qty() {
  var harga = document.f_so.harga.value;
  if(harga.length == 0) harga = "0";	

  var qty = document.f_so.qty.value;
  qty = qty.replace(/[^0-9.]/g,"");
  qty = qty.replace(".","");
  qty = qty.replace(".","");
  if(qty.length == 0) qty = "0";	
  
  var total = parseFloat(harga) * qty;

  if(qty.length > 0) {
    if(!isNaN(qty)) {
      document.f_so.qty.value = qty;
      document.f_so.total.value = total;
      formatNumber(document.f_so.qty,0);
      formatNumber(document.f_so.total,1);
     }	
  } else { document.f_so.qty.value = "0"; }			

}

function format_disc() {
  var harga = document.f_so.harga.value;
  harga = harga.replace(/[^0-9.]/g,"");
  harga = harga.replace(".","");
  harga = harga.replace(".","");
  if(harga.length == 0) harga = "0";	

  var qty = document.f_so.qty.value;
  qty = qty.replace(/[^0-9.]/g,"");
  qty = qty.replace(".","");
  qty = qty.replace(".","");
  if(qty.length == 0) qty = "0";	

  var disc = document.f_so.disc.value;
  if(disc.length == 0) disc = "0";
  
  var total = harga * qty * ( 100 - disc)/100;

  if(qty.length > 0) {
    if(!isNaN(qty)) {
      document.f_so.qty.value   = qty;
      document.f_so.total.value = total;
      document.f_so.disc.value  = disc;
      formatNumber(document.f_so.qty,0);
      formatNumber(document.f_so.total,0);
     }	
  } else { document.f_so.qty.value = "0"; }			
}

    function hapus(brg){
        var agree = confirm("Anda Yakin Ingin Menghapus " +  brg  + "?");
        if(agree){
            return true;
        }else{
            return false;
        }
    }

$(function () {
  $("#phg").change(function () {
	//var prokode = document.f_so.prokode.value;
    //$("#harga").load('<?php echo site_url()?>/transaksi/sales_order/pilih_harga?phg=' + $(this).val()+ '&prokode='+prokode);
    $.get('<?php echo site_url()?>/transaksi/sales_order/pilih_harga',{ 
	        phg:$(this).val(),
	        prokode: document.f_so.prokode.value
        } ,function(data) {
            document.f_so.harga.value = data;
            var qty   = document.f_so.qty.value;
            var harga = document.f_so.harga.value;
			var disc = document.f_so.disc.value;            
            
            var total = harga * qty * ( 100 - disc)/100;
            
            document.f_so.total.value = total;
    });
  });
});

function out(j){
	var n = document.f_so.nm.value;
	//alert(n);
	var total_1 = 0;
	var total_2 = 0;
	var totrd = 0;

	for(var i=0;i<n;i++){
		harga2  = document.f_so.elements['harga2'+i].value;
		diskon2 = document.f_so.elements['diskon2' + i].value;	 
		qty2    = document.f_so.elements['qty2' + i].value; 	
			
		total_1  = parseInt(total_1) + parseInt(harga2.replace(/\./g,'')) * qty2;
		total_2  = parseInt(total_2) + parseInt(harga2.replace(/\./g,'')) * qty2 * (100 - diskon2.replace(/\./g,'')) / 100;
		total2   = parseInt(harga2.replace(/\./g,'')) * qty2 * (100 - diskon2.replace(/\./g,'')) / 100;
		document.f_so.elements['total2' + i].value  = total2;
	}	
	//alert(total_2);
	potongan = total_1 - total_2;
	document.f_so.total_1.value  = total_1;
	document.f_so.total_2.value  = total_2;
	document.f_so.potongan.value = potongan;
	//formatNumber(document.f_so.total_1,0);
}

function tambah(){
	window.open('<?php echo site_url()?>/transaksi/sales_order_out/tambah_item?soid=<?php echo $noso;?>','destination','title=tambah item,top=100,left=500,position=center,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=600,height=300');
}

<?php
if(!empty($alert)){
	$alert = $this->session->flashdata('alert');
	echo "alert('$alert');";
}
?>
</script>    
